Ext.define('js.ledger.LedgerShowPage', {
    extend: 'Ext.panel.Panel',
    id:'LedgerShowPage',
    requires: ['js.Util', 'js.ctrl.Common',],
    controller: 'Common',
    bodyStyle:{
        background:'#eee'
    },
    height:'120%',
    width:'120%',
    pageNum:1,
    initComponent: function () {
        let lefgerPanesGroup = {
            itemId: 'lefgerPanesGroup',
            id:'lefgerPanesGroup',
            xtype: 'panel',
            margin:'0 0 20 0',
            width: '100%',
            height:'100%',
            items: [{
                html: '<div class = "bg-onday-alarm_num"><center>暂无数据</center></div>'
            }]
        }
        this.items = [
            {
                xtype: 'form',
                border:false,
                margin:'0 0 -20 0',
                layout: {
                    type: 'hbox',
                },
                bodyStyle:{
                    background:'#eee'
                },
                items: [
                    {
                        xtype: 'combobox',
                        emptyText: '工程名称',
                        triggerAction: 'all',
                        height: 30,
                        width: '25%',
                        id:'proName',
                        margin:'0 58% 30 29%',
                        labelSeparator: '',
                        labelWidth: 70,
                        editable: false,
                        displayField: 'dataType',
                        valueField: 'value',
                        store:  Ext.create('js.store.wide.projectNameStore'),
                        listeners: {
                            change: function (com, newValue, oldValue, eOpts) {//企业ID
                                let me=Ext.getCmp('LedgerShowPage');
                                me.selectResult(newValue,null);
                            }
                        }
                    },
                    {
                        xtype: 'textfield',
                        height:30,
                        width:'25%',
                        id:'ss',
                        margin:'0 40% 0 29% ',
                        value: '工程名称,地点',
                        listeners:{
                            focus: function(){
                                Ext.getCmp('ss').setValue('')
                            },
                            specialkey:function(){
                                let valueA = Ext.getCmp('ss').getValue();
                                let me=Ext.getCmp('LedgerShowPage');
                                me.selectResult(null,valueA);

                            }
                        }
                    },
                    {
                        xtype : "button",
                        text:'刷新',
                        cls:'button-Intelligent-sensor',
                        style:"cursor:pointer",
                        margin:'0 5% 0 29%',
                        handler: this.refresh,
                        scope: this,
                        width: '9.5%',
                        height: 32,
                    }
                ],
            },
            {
                items: [
                    lefgerPanesGroup,
                    {
                        xtype: 'panel',
                       /* bodyStyle:{
                            background:'#eee'
                        },*/
                        html:'<div id="LedgerShowPageSupplier" class="pagination"></div>',
                        height:50,
                        margin:'-14 0 0 0',
                        displayInfo: true,
                    }
                ]
            }];
        this.on('render', function (me, arg) {
            me.selectResult(null, null);
        });
        this.callParent(arguments);
    },
    callback:function (cd,dataTotal,pageNum,pageTotal) {
        let me = Ext.getCmp('LedgerShowPage');
        if(me){
            if(cd>0){
                new Page({
                    id: 'LedgerShowPageSupplier',
                    pageTotal:pageTotal, //必填,总页数
                    pageAmount: 10,  //每页多少条
                    dataTotal: dataTotal, //总共多少条数据
                    curPage:pageNum, //初始页码,不填默认为1
                    pageSize: 5, //分页个数,不填默认为5
                    showPageTotalFlag:true, //是否显示数据统计,不填默认不显示
                    showSkipInputFlag:true, //是否支持跳转,不填默认不显示
                    getPage: function (page) {
                        //获取当前页数
                        me.pageNum = page;
                        let engineeringName_id = Ext.getCmp('proName').value;
                        Ext.getCmp('LedgerShowPage').selectResult(engineeringName_id,null);
                    }
                })
            }else{
                new Page({
                    id: 'LedgerShowPageSupplier',
                    pageTotal: 1, //必填,总页数
                    pageAmount: 10,  //每页多少条
                    dataTotal: 0, //总共多少条数据
                    pageSize: 5, //分页个数,不填默认为5
                    showPageTotalFlag:true, //是否显示数据统计,不填默认不显示
                    showSkipInputFlag:true, //是否支持跳转,不填默认不显示
                    getPage: function (page) {
                        //获取当前页数//刷新
                        me.pageNum = page;
                        let engineeringName_id = Ext.getCmp('proName').value;
                        Ext.getCmp('LedgerShowPage').selectResult(engineeringName_id,null);
                    }
                })
            }
        }
    },
    selectResult: function (engineeringName_id,valueName) {
        let me=Ext.getCmp('LedgerShowPage');
        let lefgerPanesGroup = Ext.ComponentQuery.query('panel[itemId=lefgerPanesGroup]')[0];//当没有报警信息的时候报警详情页面内显示的页面
        Ext.Ajax.request({
            url: '/nodeAcceptanceRoutes',
            method: "POST",
            async: true,  //异步调用AJAX
            params: {
                action_type: 'nodeAcceptanceQuery',
                pageNum:me.pageNum,
                /*engineeringNo_id:no,*/
                engineeringName_id:engineeringName_id,
                 valueName:valueName
            },
            success: function (response, opts) {
                lefgerPanesGroup.removeAll(true);//此时已经有数据，移除原本没有数据时显示的页面
                let result = Ext.decode(response.responseText);//获取数据
                let cd=result.data.dataList.length;
                let dataTotal = result.data.dataTotal;
                let pageNum = result.data.pageNum;
                let pageTotal = result.data.pageTotal;
                //创建分页
                Ext.getCmp('LedgerShowPage').callback(cd,dataTotal,pageNum,pageTotal);
                //暂无数据
                if ((result.success === false) || (result.data.dataList.length < 1)) {
                    lefgerPanesGroup.removeAll(true);
                    lefgerPanesGroup.add({html: '<div class = "bg-onday-alarm_num"><center>暂无数据</center></div>'});
                    return;
                }
                let htmlObj='';
                //循环输出数据
                for(let i=0; i<result.data.dataList.length; i++){
                    htmlObj +=`
                               <div style="height:30px;background:#eee"></div>                                                                     

                                <div><table border= "1px solid black"  class="ptable" style="background-color:#ffffff" width= "100% " >
                                        <tr>
                                            <td style="text-align: center;font-weight: 800;font-size: 18px;color:#000">
                                                序号:${result.data.dataList[i][0][0].engineering_no}
                                            </td>
                                            <td style="text-align: center;font-weight: 800;font-size: 18px;color:#000">
                                                工程名称:${result.data.dataList[i][0][0].engineering_name}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td   width= "25%" style="text-align: center;font-size: 18px;color:#000"> 基础验收　 </td>
                                            <td   width= "75%">
                                                <table  width= "100% ">
                                                    <tr class="ptrcolor">
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">材料报送时间</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">验收时间</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">监督人员</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">监督记录及整改通知和回复</td>
                                                    </tr>`;
                    //基础验收循环
                    if(result.data.dataList[i][1].length<1){
                        htmlObj +=`
                                                                    <tr class="ptrborder">
                                                                        <td colspan="4"  style="text-align: center; height:100px;">
                                                                        暂无数据
                                                                        </td>
                                                                     
                                                                    </tr>
                                                                    `

                    }else{
                        for(let a=0; a<result.data.dataList[i][1].length; a++){
                            htmlObj +=`
                                                                    <tr class="ptrborder">
                                                                        <td style="text-align: center;">${result.data.dataList[i][1][a].inspection_date}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][1][a].supervision_date}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][1][a].userName}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][1][a].remarks}</td>
                                                                    </tr>
                                                                    `
                        }
                    }
                    htmlObj +=`
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td   width= "25%" style="text-align: center;font-size: 18px;color:#000"> 主体验收 </td>
                                            <td   width= "75%">
                                                <table width= "100% ">
                                                    <tr class="ptrcolor">
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">材料报送时间</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">验收时间</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">监督人员</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">监督记录及整改通知和回复</td>
                                                    </tr>`;
                    //主体验收循环
                    if(result.data.dataList[i][2].length<1){
                        htmlObj +=`
                                                           <tr class="ptrborder">
                                                                  <td colspan="4"  style="text-align: center; height:100px;">
                                                                    暂无数据
                                                                    </td>                                  
                                                                  </tr>
                                                                   `
                    }else {
                        for (let b = 0; b < result.data.dataList[i][2].length; b++) {
                            htmlObj += `
                                                                    <tr class="ptrborder">
                                                                        <td style="text-align: center;">${result.data.dataList[i][2][b].inspection_date}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][2][b].supervision_date}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][2][b].userName}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][2][b].remarks}</td>
                                                                    </tr>
                                                                    `
                        }
                    }
                    htmlObj +=`
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td   width= "25%" style="text-align: center;font-size: 18px;color:#000"> 竣工验收　 </td>
                                            <td   width= "75%">
                                                <table  width= "100% ">
                                                    <tr class="ptrcolor">
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">材料报送时间</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">审查通过时间</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">验收时间</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">监督人员</td>
                                                        <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">监督记录及整改通知和回复</td>
                                                    </tr>
                                                    `;
                    //竣工验收循环
                    if(result.data.dataList[i][3].length<1){
                        htmlObj +=`
                                                           <tr class="ptrborder">
                                                                  <td colspan="4"  style="text-align: center; height:100px;">
                                                                    暂无数据
                                                                    </td>                                  
                                                                  </tr>
                                                                   `
                    }else {
                        for (let c = 0; c < result.data.dataList[i][3].length; c++) {
                            htmlObj += `
                                                                    <tr class="ptrborder">
                                                                        <td style="text-align: center;">${result.data.dataList[i][3][c].inspection_date}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][3][c].review_pass_date}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][3][c].completion_date}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][3][c].userName}</td>
                                                                        <td style="text-align: center;">${result.data.dataList[i][3][c].remarks}</td>
                                                                    </tr>
                                                                    `
                        }
                    }
                    htmlObj +=`
                                                                        </table>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td   width= "25%" style="text-align: center;font-size: 18px;color:#000"> 竣工验收备案　 </td>
                                                                    <td   width= "75%">
                                                                        <table    width= "100% ">
                                                                            <tr class="ptrcolor">
                                                                                <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">材料报送时间</td>
                                                                                <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">备案时间</td>
                                                                                <td style="text-align: center;color: #000000;font-weight: 600;font-size: 18px;">资料缺项记录</td>
                                                                            </tr>
                                                                            `;
                    //竣工验收备案循环
                    if(result.data.dataList[i][4].length<1){
                        htmlObj +=`
                                                           <tr class="ptrborder">
                                                                  <td colspan="4"  style="text-align: center; height:100px;">
                                                                    暂无数据
                                                                    </td>                                  
                                                                  </tr>
                                                                   `
                    }else {
                        for (let d = 0; d < result.data.dataList[i][4].length; d++) {
                            htmlObj += `
                                                                        <tr class="ptrborder">
                                                                            <td style="text-align: center;">${result.data.dataList[i][4][d].inspection_date}</td>
                                                                            <td style="text-align: center;">${result.data.dataList[i][4][d].filing_date}</td>
                                                                            <td style="text-align: center;">${result.data.dataList[i][4][d].remarks}</td>
                                                                        </tr>
                                                                        `
                        }
                    }
                    htmlObj +=`
                                                                                </table>
                                                                    
                                                                            </td>
                                                                        </tr>
                                                                    
                                                                    </table></div>
                                                                    `
                }
                let htmlObjA={html:htmlObj};
                lefgerPanesGroup.add(htmlObjA);

            },
            failure: function () {
                Ext.toast(`获取异常报警数据失败：${response.status}`);
            }  // 请求失败的回调函数
        });
    },
    refresh: function (btn) {
        Ext.getCmp('ss').setValue('');
        Ext.getCmp('proName').setValue('');
        let ss = '';
        let proName = '';
        this.selectResult(proName,ss);


    }
});